﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace CalcSharp.Core.Controlls
{
    public class ToolStripTrackBar : ToolStripControlHost
    {
        public ToolStripTrackBar(): base(new TrackBar())
        {
            this.TrackBarControl.TickFrequency = 10;
            this.TrackBarControl.BackColor = Color.FromKnownColor(KnownColor.Control);
            this.TrackBarControl.AutoSize = false;
            if (Parent != null)
            {
                this.BackColor = Parent.BackColor;
                this.TrackBarControl.BackColor = Parent.BackColor;
            }
        }

        public TrackBar TrackBarControl
        {
            get { return (TrackBar)this.Control; }
        }

        public int Value
        {
            get { return TrackBarControl.Value; }
            set { TrackBarControl.Value = value; }
        }

        public int Minimum
        {
            get { return TrackBarControl.Minimum; }
            set { TrackBarControl.Minimum = value; }
        }

        public int Maximum
        {
            get { return TrackBarControl.Maximum; }
            set { TrackBarControl.Maximum = value; }
        }

        protected override void OnSubscribeControlEvents(Control control)
        {
            base.OnSubscribeControlEvents(control);
            TrackBar TrackBar = (TrackBar)control;
            TrackBar.Scroll += new EventHandler(HandleScroll);
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {
            base.OnUnsubscribeControlEvents(control);
            TrackBar TrackBar = (TrackBar)control;
            TrackBar.Scroll -= HandleScroll;
        }

        public event EventHandler Scroll;

        private void HandleScroll(object sender, EventArgs e)
        {
            if (this.Scroll != null) this.Scroll(this, e);
        }
    }
}
